package com.yoshino.factory.abstract_factory.order;

import com.yoshino.factory.abstract_factory.pizza.Pizza;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author yoshino
 **/
@Slf4j
public class OrderPizza {

    AbsFactory absFactory;

    public OrderPizza(AbsFactory factory){
        setAbsFactory(factory);
    }

    private void setAbsFactory(AbsFactory factory) {
        Pizza pizza = null;
        //用户输入
        String orderType="";
        this.absFactory = factory;
        do {
            pizza = absFactory.createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                log.info("失败");
                break;
            }
        } while (true);


    }


    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            log.info("input pizza type:");
            return strin.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }

    }

}
